package com.jxgyl.gateway.service.impl;

import com.jxgyl.api.RemoteTestService;
import com.jxgyl.common.data.R;
import com.jxgyl.gateway.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @program: middleplatform
 * @description: gateway中用openfeign调用，一定要用异步调用，并用future获取，注入的远程调用类，一定要用@Lazy，目前还不知道为什么。。。。
 * @author: Wanglipeng
 * @create: 2022-01-27 17:13
 **/
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    @Lazy
    RemoteTestService remoteTestService;

    @Override
    @Async
    public Future<String> test() {
        R<String> r = remoteTestService.test("okaoka");
        return new AsyncResult<>(r.getData());
    }
}
